package com.ymatou.iapi.productmanager.testcase;
import java.util.Arrays;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.service.GetProductCheckStatusListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.productdata.impl.ProductFactory;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;

public class Ts_GetProductCheckStatusList {
	private static IntergratedProductMapper intergratedProductMapper = SqlMapperFactory.getIntergratedProductMapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询商品checkstatus");
	}
	
	@Before
	public void caseUp() {
	}
	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(new GetProductCheckStatusListCall().getOpurl());
	}
	
	@After
	public void caseDown() {
		Logger.end(); 
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductCheckStatusList_001() throws Exception {
		Logger.start(true,"查询商品checkstatus");
		try{
			String productId1 = ProductFactory.getOnlyProduct().getProductId();
			String productId2 = ProductFactory.getOnlyProduct().getProductId();
			
			int status1 = (Integer)intergratedProductMapper.selectProductByProdId(productId1).get("CheckStatus");
			int status2 = (Integer)intergratedProductMapper.selectProductByProdId(productId2).get("CheckStatus");
			
			JSONObject ret = new GetProductCheckStatusListCall().call(Arrays.asList(productId1,productId2));
			Logger.verifyEquals(200,ret.getInt("Code"), "返回码校验");
			
			
			String actProd1 = ret.getJSONObject("Data").getJSONArray("CheckStatusList").getJSONObject(0).getString("ProductId");
			String actProd2 = ret.getJSONObject("Data").getJSONArray("CheckStatusList").getJSONObject(1).getString("ProductId");
			
			int actStatus1 = ret.getJSONObject("Data").getJSONArray("CheckStatusList").getJSONObject(0).getInt("CheckStatus");
			int actStatus2 = ret.getJSONObject("Data").getJSONArray("CheckStatusList").getJSONObject(1).getInt("CheckStatus");
			
			if (actProd1.equals(productId1)){
				Logger.verifyEquals(productId1, actProd1, "商品ID");
				Logger.verifyEquals(productId2, actProd2, "商品ID");
				Logger.verifyEquals(status1, actStatus1, "checkstauts");
				Logger.verifyEquals(status2, actStatus2, "checkstauts");
				
			}else{
				Logger.verifyEquals(productId1, actProd2, "商品ID");
				Logger.verifyEquals(productId2, actProd1, "商品ID");
				Logger.verifyEquals(status1, actStatus2, "checkstauts");
				Logger.verifyEquals(status2, actStatus1, "checkstauts");
				
			}
			
			
			
		}catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductCheckStatusList_002() throws Exception {
		Logger.start(true,"查询商品checkstatus 商品id不存在");
		try{
			
			
			JSONObject ret = new GetProductCheckStatusListCall().call(Arrays.asList("dsfsdfdsfdf"));
			Logger.verifyEquals(200,ret.getInt("Code"), "返回码校验");
			Logger.verifyEquals(true, ret.getJSONObject("Data").isNull("CheckStatusList"), "CheckStatusList 应为null");
			
			
		}catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	
	
}
